<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // f1();
        //async方法中，可用await
        async function f1(){
            console.log('enter f1');
            let money = await new Promise((resove,reject)=>{
                setTimeout(()=>{
                    resove(100);
                },1000)
            });
            console.log('money',money);
            let isOk = await new Promise((resove,reject)=>{
                setTimeout(()=>{
                    resove(true);
                },1000)
            })
            console.log('isOk',isOk);

            console.log('end f1');
        }
    </script>
    <script>
        f2();
        async function f2(){
            console.log('enter f2');
            let money = await getMoney();
            console.log('money',money);
            let isOk = await costMoney();
            console.log('isOk',isOk);

            console.log('end f2');
        }

        function getMoney(){
            return new Promise((resove,reject)=>{
                setTimeout(()=>{
                    resove(100);
                },1000)
            });
        }

        function costMoney(){
            return new Promise((resove,reject)=>{
                setTimeout(()=>{
                    resove(true);
                },1000)
            });
        }
    </script>
</body>
</html>